/*
 * Created by SharpDevelop.
 * User: mac
 * Date: 06.09.2006
 * Time: 21:13
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Timers;
using System.Collections.Generic;
using CsGL;
using CsGL.OpenGL;
using TagTool.Core;
using TagTool.OpenGL;
using TagTool.GraphicTypes;

namespace TagTool.Nodes.Graphic
{
	
		
	public class Fade : BaseNode
	{
		private InputSlot shape;
		private InputSlot alpha;
	
		
		public Fade()
		{
			Name = "Fade Out and Delete";
					
			shape = new InputSlot(this, "Input Shape", new Shape());
			alpha = new InputSlot(this, "Aplha", 0.05);
			alpha.ParseCallback = ParseHelper.ParseDouble;
		}
		
		public override void Update(Object sender)
		{
			
			if (shape.Value is TagTool.GraphicTypes.Scene)
			{
				List<Shape> shapes = ((TagTool.GraphicTypes.Scene)shape.Value).Shapes;
				lock(shapes)
				{
					int i = 0;
					Shape s;
					for(i = 0; i < shapes.Count; i++)
					{
						s = shapes[i];
						s.Alpha = s.Alpha - (double)alpha.Value;
						if (s.Alpha <= 0.0)
						{
							shapes.RemoveAt(i--);
						}
					}
				}
				TriggerOut.Value = shapes.Count == 0;
				
			}
			else
			{
				((Shape)shape.Value).Alpha = ((Shape)shape.Value).Alpha - (double)alpha.Value;
			}
		}
		

		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Alpha
		{
			get { return alpha; }
		}
		
		[NodeAttribute(SlotType.Input, Show = true)]
		public InputSlot Shape
		{
			get { return shape; }
		}
	}
}
